<!-- home -->
<template>
  <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <van-cell v-for="item in list" :key="item" :title="item" />
    </van-list>
  </van-pull-refresh>
</template>

<script>
// import { api } from '@/config'
import { List, Cell, PullRefresh } from 'vant'
export default {
  components: {
    'van-list': List,
    'van-cell': Cell,
    'van-pull-refresh': PullRefresh
  },

  data() {
    return {
      isLoading: false,
      list: [],
      loading: false,
      finished: false
    }
  },

  computed: {},

  created() {
    console.log(this.$route)
  },

  mounted() {},

  methods: {
    onLoad() {
      console.log(22)
      // 异步更新数据
      setTimeout(() => {
        for (let i = 0; i < 20; i++) {
          this.list.push(this.list.length + 1)
        }
        // 加载状态结束
        this.loading = false

        // 数据全部加载完成
        // if (this.list.length >= 40) {
        //   this.finished = true;
        // }
      }, 1000)
    },
    onRefresh() {
      setTimeout(() => {
        this.$toast('刷新成功')
        this.isLoading = false
      }, 1000)
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
